using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.Linq;
using DotNetNuke.Common.Utilities;

namespace Code5Systems.FormMaster.Business
{

	public partial class FormDataController : DotNetNuke.Entities.Modules.IPortable
	{
		
		private FormSettings objFormSettings = new FormSettings();
		
#region Optional Interfaces
		
		public string ExportModule(int ModuleID)
		{
			
			StringBuilder strXML = new StringBuilder();
			
			FormController objFormCtl = new FormController(ModuleID);
			FormInfo objFormInfo = objFormCtl.FormInfo;
			FormSettings objFormSettings = Utility.GetFormSettings(ModuleID);
			FormFieldRulesController oFieldRulesCtl = new FormFieldRulesController();
			
			strXML.Append("<Form>");
			
			// Base Form Data
			objFormInfo.ConnectionString = Utility.EncryptString(objFormInfo.ConnectionString);
			string serializedFormInfo = (string) (Utility.XmlSerialize<FormInfo>(objFormInfo));
			strXML.Append(serializedFormInfo);
			
			//The Module Settings
			
			//Last Report Date has no meaning when importing a form
			objFormSettings.LastReportDate = DateTime.MinValue;
			
			// If the original form redirected to either a page on the site or to a file
			// the reference will probably be bad so default to "None"
			objFormSettings.RedirectType = "N";
			
			// When Importing to another module it's likely that a custom style sheet will not be present
			// so default this setting to false
			objFormSettings.UseCustomXslt = false;
			
			string serializedSettings = (string) (Utility.XmlSerialize<FormSettings>(objFormSettings));
			strXML.Append(serializedSettings);
			
			// Field Rules
			strXML.Append("<FieldRules>");
			List<FormFieldRulesInfo> aryFieldRules = oFieldRulesCtl.GetByForm(objFormInfo.FormID);
			if (aryFieldRules.Count > 0)
			{
				foreach (FormFieldRulesInfo rule in aryFieldRules)
				{
					strXML.Append("<Rule>");
					strXML.Append("<SourceField>" + rule.SourceField + "</SourceField>");
					strXML.Append("<SourceFieldName>" + rule.SourceFieldName + "</SourceFieldName>");
					strXML.Append("<ContainsValue>" + rule.ContainsValue + "</ContainsValue>");
					strXML.Append("<FieldType>" + rule.FieldType + "</FieldType>");
					strXML.Append("<FormFields>" + rule.FormFields + "</FormFields>");
					strXML.Append("</Rule>");
				}
			}
			strXML.Append("</FieldRules>");
			
			// Field Mappings when External Data is used
			strXML.Append("<FormMappigs>");
			FormMappingController objFormMapCtl = new FormMappingController();
			List<FormMappingInfo> Mappings = objFormMapCtl.GetByForm(objFormInfo.FormID);
			if (Mappings.Count > 0)
			{
				foreach (FormMappingInfo mapInfo in Mappings)
				{
					strXML.Append("<Mapping>");
					strXML.Append("<FormField>" + mapInfo.FormField + "</FormField>");
					strXML.Append("<FormFieldLabel>" + mapInfo.FormFieldLabel + "</FormFieldLabel>");
					strXML.Append("<TableField>" + mapInfo.TableField + "</TableField>");
					strXML.Append("<DataType>" + mapInfo.DataType + "</DataType>");
					strXML.Append("<Length>" + mapInfo.Length.ToString() + "</Length>");
					strXML.Append("<Prec>" + mapInfo.Prec + "</Prec>");
					strXML.Append("<Scale>" + mapInfo.Scale + "</Scale>");
					strXML.Append("<Nullable>" + mapInfo.Nullable.ToString().ToLower() + "</Nullable>");
					strXML.Append("<Value>" + mapInfo.Value + "</Value>");
					strXML.Append("<PageNum>" + mapInfo.PageNum.ToString() + "</PageNum>");
					strXML.Append("</Mapping>");
				}
			}
			
			strXML.Append("</FormMappigs>");
			
			strXML.Append("<FormDefinition>" + objFormInfo.FormDefinition + "</FormDefinition>");
			
			// Form Pages
			strXML.Append("<Pages>");
			FormPageController pageCtlr = new FormPageController();
			List<FormPageInfo> pages = pageCtlr.ListFormPagesByFormID(objFormInfo.FormID);
			foreach (FormPageInfo item in pages)
			{
				strXML.Append("<Page>" + Utility.XmlSerialize<FormPageInfo>(item) + "</Page>");
			}
			strXML.Append("</Pages>");
			
			strXML.Append("</Form>");
			
			return strXML.ToString();
			
		}
		
		public void ImportModule(int ModuleID, string Content, string Version, int UserId)
		{
			
			FormController objFormCtl = new FormController(ModuleID);
			FormInfo objFormInfo = default(FormInfo);
			FormFieldRulesController oFieldRulesCtl = new FormFieldRulesController();
			HttpContext oContext = HttpContext.Current;
			
			if (DotNetNuke.Common.Globals.GetContent(Content, "//Form/FormInfo") != null)
			{
				objFormInfo = Utility.XmlDeserialize<FormInfo>(DotNetNuke.Common.Globals.GetContent(Content, "//Form/FormInfo").OuterXml);
				objFormInfo.ConnectionString = Utility.DecryptString(objFormInfo.ConnectionString);
			}
			else
			{
				objFormInfo = GetLegacyFormInfo(ModuleID, UserId, Content);
			}
			
			objFormInfo.PortalID = DotNetNuke.Entities.Portals.PortalSettings.Current.PortalId;
			objFormInfo.ModuleID = ModuleID;
			objFormInfo.FormID = objFormCtl.FormInfo.FormID;
			objFormInfo.LastModifiedByID = UserId;
			
			// Save the Form
			// Form is created when module is placed on the page
			// no need for the Add Method
			if (objFormCtl.FormInfo == null)
			{
				objFormInfo.FormID = objFormCtl.Add(objFormInfo);
			}
			else
			{
				objFormCtl.Update(objFormInfo);
			}
			
			// Form Settings
			if (DotNetNuke.Common.Globals.GetContent(Content, "//Form/FormSettings") != null)
			{
				DeserializeSettings(Content);
			}
			else
			{
				GetLegacySettings(Content);
			}
			
			// Save Module Settings
			Utility.SaveFormSettings(ModuleID, objFormSettings);
			oContext.Cache.Remove("C5SLLC_FormSettings_" + ModuleID.ToString());
			
			//Get the Field Rules
			
			FormFieldRulesInfo fieldRule = default(FormFieldRulesInfo);
			XmlDocument contentXml = new XmlDocument();
			contentXml.LoadXml(Content);
			
			//Delete any existing Rules since they may not apply to this form
			oFieldRulesCtl.DeleteFormFieldRulesByForm(objFormInfo.FormID);
			
			XmlNodeList rules = contentXml.SelectNodes("//Form/FieldRules/Rule");
			if (rules.Count > 0)
			{
				for (int i = 0; i <= rules.Count - 1; i++)
				{
					fieldRule = new FormFieldRulesInfo();
					fieldRule.FormID = objFormInfo.FormID;
					fieldRule.SourceField = (string) (rules[i].SelectSingleNode("SourceField").InnerText);
					fieldRule.SourceFieldName = (string) (rules[i].SelectSingleNode("SourceFieldName").InnerText);
					fieldRule.ContainsValue = (string) (rules[i].SelectSingleNode("ContainsValue").InnerText);
					fieldRule.FieldType = byte.Parse((string) (rules[i].SelectSingleNode("FieldType").InnerText));
					fieldRule.FormFields = (string) (rules[i].SelectSingleNode("FormFields").InnerText);
					oFieldRulesCtl.Add(fieldRule);
				}
			}
			
			// Get the Pages
			FormPageInfo pageInfo = default(FormPageInfo);
			FormPageController pageCtlr = new FormPageController();
			pageCtlr.DeleteFormPageByFormID(objFormInfo.FormID);
			XDocument xDoc = XDocument.Parse(Content);
			
			IEnumerable<XElement> xPages = from c in xDoc.Descendants("FormPage") select c;
			
			foreach (XElement item in xPages)
			{
				pageInfo = Utility.XmlDeserialize<FormPageInfo>(item.ToString());
				pageInfo.FormID = objFormInfo.FormID;
				pageCtlr.AddFormPage(pageInfo);
			}
			
			// Get the Field Mappings for External Data
			//Delete any existing Mappings
			FormMappingController objFormMapCtl = new FormMappingController();
			objFormMapCtl.Delete(objFormInfo.FormID);
			FormMappingInfo oMapping = default(FormMappingInfo);
			List<FormMappingInfo> mappingList = default(List<FormMappingInfo>);
			XmlNodeList mappings = contentXml.SelectNodes("//Form/FormMappigs/Mapping");
			if (mappings.Count > 0)
			{
				mappingList = new List<FormMappingInfo>();
				for (int i = 0; i <= mappings.Count - 1; i++)
				{
					oMapping = new FormMappingInfo();
					oMapping.FormID = objFormInfo.FormID;
					oMapping.FormField = (string) (mappings[i].SelectSingleNode("FormField").InnerText);
					oMapping.FormFieldLabel = (string) (mappings[i].SelectSingleNode("FormFieldLabel").InnerText);
					oMapping.TableField = (string) (mappings[i].SelectSingleNode("TableField").InnerText);
					oMapping.DataType = (string) (mappings[i].SelectSingleNode("DataType").InnerText);
					oMapping.Length = System.Convert.ToInt32(mappings[i].SelectSingleNode("Length").InnerText);
					oMapping.Prec = System.Convert.ToByte(mappings[i].SelectSingleNode("Prec").InnerText);
					oMapping.Scale = System.Convert.ToByte(mappings[i].SelectSingleNode("Scale").InnerText);
					oMapping.Nullable = System.Convert.ToBoolean(mappings[i].SelectSingleNode("Nullable").InnerText);
					oMapping.Value = (string) (mappings[i].SelectSingleNode("Value").InnerText);
					if (mappings[i].SelectSingleNode("PageNum") != null)
					{
						oMapping.PageNum = System.Convert.ToInt32(mappings[i].SelectSingleNode("PageNum").InnerText);
					}
					else
					{
						oMapping.PageNum = 1;
					}
					mappingList.Add(oMapping);
				}
				objFormMapCtl.Add(mappingList);
			}
			
		}
		
#endregion
		
#region Private Methods
		
		private FormInfo GetLegacyFormInfo(int ModuleID, int UserID, string Content)
		{
			FormInfo objFormInfo = default(FormInfo);
			FormController objFormCtl = new FormController(ModuleID);
			XmlNode xmlFormData = default(XmlNode);
			
			//Form is created when module is placed on the page
			// We will always have a form object.
			objFormInfo = objFormCtl.FormInfo;
			if (objFormInfo == null)
			{
				objFormInfo = new FormInfo();
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/BccAddress");
			if (xmlFormData != null)
			{
				objFormInfo.BccAddress = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/EmailSendAction");
			if (xmlFormData != null)
			{
				objFormInfo.EmailSendAction = byte.Parse(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/EmailSendTo");
			if (xmlFormData != null)
			{
				objFormInfo.EmailSendTo = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/EmailSendToControl");
			if (xmlFormData != null)
			{
				objFormInfo.EmailSendToControl = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/FormName");
			if (xmlFormData != null)
			{
				objFormInfo.FormName = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/FromAddress");
			if (xmlFormData != null)
			{
				objFormInfo.FromAddress = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ReplyToAction");
			if (xmlFormData != null)
			{
				objFormInfo.ReplyToAction = byte.Parse(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ReplyTo");
			if (xmlFormData != null)
			{
				objFormInfo.ReplyTo = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ReplyToControl");
			if (xmlFormData != null)
			{
				objFormInfo.ReplyToControl = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/LabelPosition");
			if (xmlFormData != null)
			{
				objFormInfo.LabelPosition = byte.Parse(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/SaveData");
			if (xmlFormData != null)
			{
				objFormInfo.SaveData = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/TableClass");
			if (xmlFormData != null)
			{
				objFormInfo.TableClass = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/TableColumns");
			if (xmlFormData != null)
			{
				objFormInfo.TableColumns = byte.Parse(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/TableRows");
			if (xmlFormData != null)
			{
				objFormInfo.TableRows = byte.Parse(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/FormDefinition");
			if (xmlFormData != null)
			{
				objFormInfo.FormDefinition = Utility.FixLegacyLabels(xmlFormData.InnerXml);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ShowCCMe");
			if (xmlFormData != null)
			{
				objFormInfo.ShowCcMe = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/EmailCcMeControl");
			if (xmlFormData != null)
			{
				objFormInfo.EmailCcMeControl = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/UseCaptcha");
			if (xmlFormData != null)
			{
				objFormInfo.UseCaptcha = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/CaptchaCharacters");
			if (xmlFormData != null)
			{
				objFormInfo.CaptchaCharacters = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ConnectionString");
			if (xmlFormData != null)
			{
				objFormInfo.ConnectionString = Utility.DecryptString(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/FormQuery");
			if (xmlFormData != null)
			{
				objFormInfo.FormQuery = xmlFormData.InnerText;
			}
			
			int exportedModuleID = Null.NullInteger;
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ExportedModuleID");
			if (xmlFormData != null)
			{
				exportedModuleID = int.Parse(xmlFormData.InnerText);
			}
			
			//We only want to import External Table Information it the Import is
			//in the Same module as the Export.
			//Eternal Table Data
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/UseExtTable");
			if (xmlFormData != null)
			{
				objFormInfo.UseExtTable = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ExtTableConnStr");
			if (xmlFormData != null)
			{
				objFormInfo.ExtTableConnStr = Utility.DecryptString(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ExtTableName");
			if (xmlFormData != null)
			{
				objFormInfo.ExtTableName = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ExtIdentityColumn");
			if (xmlFormData != null)
			{
				objFormInfo.ExtIdentityColumn = xmlFormData.InnerText;
			}
			
			return objFormInfo;
		}
		
		private void DeserializeSettings(string Content)
		{
			XmlNode xmlFormData = default(XmlNode);
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/FormSettings");
			if (xmlFormData != null)
			{
				objFormSettings = Utility.XmlDeserialize<FormSettings>(xmlFormData.OuterXml);
			}
		}
		
		private void GetLegacySettings(string Content)
		{
			XmlNode xmlFormData = default(XmlNode);
			//Form Settings
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/AllowAnonUploads");
			if (xmlFormData != null)
			{
				objFormSettings.AllowAnonUploads = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/AuthFileDownloads");
			if (xmlFormData != null)
			{
				objFormSettings.AuthFileDownloads = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/HidePostedBy");
			if (xmlFormData != null)
			{
				objFormSettings.HidePostedBy = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/InSurveyMode");
			if (xmlFormData != null)
			{
				objFormSettings.InSurveyMode = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/TableAlignment");
			if (xmlFormData != null)
			{
				switch (xmlFormData.InnerText)
				{
					case "NotSet":
						objFormSettings.TableAlignment = HorizontalAlign.NotSet;
						break;
					case "Left":
						objFormSettings.TableAlignment = HorizontalAlign.Left;
						break;
					case "Center":
						objFormSettings.TableAlignment = HorizontalAlign.Center;
						break;
					case "Right":
						objFormSettings.TableAlignment = HorizontalAlign.Right;
						break;
				}
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/FormTableAlignment");
			if (xmlFormData != null)
			{
				switch (xmlFormData.InnerText)
				{
					case "NotSet":
						objFormSettings.FormTableAlignment = HorizontalAlign.NotSet;
						break;
					case "Left":
						objFormSettings.FormTableAlignment = HorizontalAlign.Left;
						break;
					case "Center":
						objFormSettings.FormTableAlignment = HorizontalAlign.Center;
						break;
					case "Right":
						objFormSettings.FormTableAlignment = HorizontalAlign.Right;
						break;
				}
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/SendAutoResponder");
			if (xmlFormData != null)
			{
				objFormSettings.SendAutoResponder = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/AutoRespSubject");
			if (xmlFormData != null)
			{
				objFormSettings.AutoRespSubject = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/AutoRespToField");
			if (xmlFormData != null)
			{
				objFormSettings.AutoRespToField = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/AutoRespFromEmail");
			if (xmlFormData != null)
			{
				objFormSettings.AutoRespFromEmail = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/RequiredFieldSymbol");
			if (xmlFormData != null)
			{
				objFormSettings.RequiredFieldSymbol = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/UseFieldForSubject");
			if (xmlFormData != null)
			{
				objFormSettings.UseFieldForSubject = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/SubjectFieldValue");
			if (xmlFormData != null)
			{
				objFormSettings.SubjectFieldValue = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/SubjectFieldValue2");
			if (xmlFormData != null)
			{
				objFormSettings.SubjectFieldValue2 = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/SendHtmlEmail");
			if (xmlFormData != null)
			{
				objFormSettings.SendHtmlEmail = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/TableClass");
			if (xmlFormData != null)
			{
				objFormSettings.TableClass = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/TableWidth");
			if (xmlFormData != null)
			{
				objFormSettings.TableWidth = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/TemplateType");
			if (xmlFormData != null)
			{
				switch (xmlFormData.InnerText)
				{
					case "Xsl":
						objFormSettings.TemplateType = TemplateType.XSL;
						break;
					case "Text":
						objFormSettings.TemplateType = TemplateType.Text;
						break;
					case "Custom":
						objFormSettings.TemplateType = TemplateType.Custom;
						break;
					default:
						objFormSettings.TemplateType = TemplateType.Text;
						break;
				}
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/Encoding");
			if (xmlFormData != null)
			{
				switch (xmlFormData.InnerText)
				{
					case "ASCII":
						objFormSettings.Encoding = EmailEncoding.ASCII;
						break;
					case "BigEndianUnicode":
						objFormSettings.Encoding = EmailEncoding.BigEndianUnicode;
						break;
					case "Default":
						objFormSettings.Encoding = EmailEncoding.Default;
						break;
					case "Unicode":
						objFormSettings.Encoding = EmailEncoding.Unicode;
						break;
					case "UTF32":
						objFormSettings.Encoding = EmailEncoding.UTF32;
						break;
					case "UTF7":
						objFormSettings.Encoding = EmailEncoding.UTF7;
						break;
					case "UTF8":
						objFormSettings.Encoding = EmailEncoding.UTF8;
						break;
					default:
						objFormSettings.Encoding = EmailEncoding.Default;
						break;
				}
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/SupressReqFldText");
			if (xmlFormData != null)
			{
				objFormSettings.SuppressReqFldText = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/TextTemplate");
			if (xmlFormData != null)
			{
				objFormSettings.TextTemplate = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/LastReportDate");
			if (xmlFormData != null)
			{
				objFormSettings.LastReportDate = DateTime.Parse(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/RedirectType");
			if (xmlFormData != null)
			{
				objFormSettings.RedirectType = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/RedirectUrl");
			if (xmlFormData != null)
			{
				objFormSettings.RedirectUrl = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/UseCustomXslt");
			if (xmlFormData != null)
			{
				objFormSettings.UseCustomXslt = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/UseValidationSummary");
			if (xmlFormData != null)
			{
				objFormSettings.UseValidationSummary = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ValidationSummaryCssClass");
			if (xmlFormData != null)
			{
				objFormSettings.ValidationSummaryCssClass = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ValidationSummaryHeading");
			if (xmlFormData != null)
			{
				objFormSettings.ValidationSummaryHeading = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ValidationSummaryHorzAlign");
			if (xmlFormData != null)
			{
				objFormSettings.ValidationSummaryHorzAlign = int.Parse(xmlFormData.InnerText).ToEnum<HorizontalAlign>();
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ValidationSummaryInsertAtRow");
			if (xmlFormData != null)
			{
				objFormSettings.ValidationSummaryInsertAtRow = int.Parse(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ValidationSummaryMode");
			if (xmlFormData != null)
			{
				objFormSettings.ValidationSummaryMode = int.Parse(xmlFormData.InnerText).ToEnum<ValidationSummaryDisplayMode>();
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ShowValidationSummary");
			if (xmlFormData != null)
			{
				objFormSettings.ShowValidationSummary = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/ShowValidationSummaryMessageBox");
			if (xmlFormData != null)
			{
				objFormSettings.ShowValidationSummaryMessageBox = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/SupressFieldValidationMessages");
			if (xmlFormData != null)
			{
				objFormSettings.SupressFieldValidationMessages = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/SuppressedFieldCharacter");
			if (xmlFormData != null)
			{
				objFormSettings.SuppressedFieldCharacter = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/RegisterUser");
			if (xmlFormData != null)
			{
				objFormSettings.RegisterUser = System.Convert.ToBoolean(xmlFormData.InnerText);
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/FirstNameField");
			if (xmlFormData != null)
			{
				objFormSettings.FirstNameField = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/LastNameField");
			if (xmlFormData != null)
			{
				objFormSettings.LastNameField = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/EmailField");
			if (xmlFormData != null)
			{
				objFormSettings.EmailField = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/UserNameField");
			if (xmlFormData != null)
			{
				objFormSettings.UserNameField = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/PasswordField");
			if (xmlFormData != null)
			{
				objFormSettings.PasswordField = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/UserRoles");
			if (xmlFormData != null)
			{
				objFormSettings.UserRoles = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/FormTableWidth");
			if (xmlFormData != null)
			{
				objFormSettings.FormTableWidth = xmlFormData.InnerText;
			}
			
			xmlFormData = DotNetNuke.Common.Globals.GetContent(Content, "//Form/FormTableWidth");
			if (xmlFormData != null)
			{
				objFormSettings.FormTableWidth = xmlFormData.InnerText;
			}
		}
#endregion
		
	}
	
}

